using System;
using System.Reflection;

namespace SaveGameConverter
{
    public static class ObjectExm
    {
        public static object GetPrivateFieldValue<T>(this T self, string fieldName)
        {
            if (self == null)
                throw new NullReferenceException();

            return typeof(T).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance).GetValue(self);
        }

        public static void SetPrivateFieldValue<T>(this T self, string fieldName, object value)
        {
            if (self == null)
                throw new NullReferenceException();

            typeof(T).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance).SetValue(self, value);
        }
    }
}
